﻿@Layout ~/Views/Shared/_Layout.vbhtml
@code 
    Dim showFavs As Boolean
    Dim Favs As SortedSet(Of String)
    Dim Recommended As SortedSet(Of String)
    If ViewData.TryGetValue("MarkFavorites", showFavs) AndAlso showFavs Then
        Favs = WikiModel.Instance.GetPagesByExactTag("מועדפים")
        Recommended = WikiModel.Instance.GetPagesByTag("מומלץ")
    Else
        Recommended = New SortedSet(Of String)
        Favs = New SortedSet(Of String)
    End If
End Code

@Helper WriteRecord(PageTitle As String, favs As SortedSet(Of String), recommended As SortedSet(Of String))
    Dim cls As String = ""
    If favs.Contains(PageTitle) Then
        cls = "favorite"
    ElseIf recommended.Contains(PageTitle) Then
        cls = "recommended"
    End If
    @<li class="@cls">@Html.ActionLink(PageTitle, "FetchExact", New With {.page = PageTitle}, New With {.class = "page-link"})</li>
End Helper





<h2>@ViewData("Title")</h2>
<div class="multi-column">
   @If TypeOf (ViewData("List")) Is IDictionary Then
     @For Each Pair In ViewData("List")
        @<h3>@Pair.Key</h3>
        @<ul>
            @For Each PageTitle In Pair.Value    
               @WriteRecord(PageTitle, Favs, Recommended)
           Next
        </ul>
     Next
   ElseIf TypeOf (ViewData("List")) Is IList Then
        @<ul>
            @For Each PageTitle In ViewData("List")
                @WriteRecord(PageTitle, Favs, Recommended)
            Next
        </ul>
   Else
        Throw New Exception("_PageListLayout must recieve a list or dictionary")
   End If
</div>

@RenderBody()